package com.blockmeta.bbs.businesslibrary.arouter;

import android.content.Context;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blockmeta.bbs.businesslibrary.util.AccountHelper;

/**
 * @author AirThor
 * @date 2019/6/21.
 */
@Interceptor(priority = 1)
public class LoginInterceptor implements IInterceptor {
    @Override
    public void process(Postcard postcard, InterceptorCallback callback) {
        int extra = postcard.getExtra();
        if (extra== RouterConstant.EXTRAL_LOGIN){
            if (AccountHelper.isLogin()){
                callback.onContinue(postcard);
            }else {
                callback.onInterrupt(null);
                ARouter.getInstance().build(RouterPath.ACCOUNT_LOGIN_ACTIVITY).navigation();
            }
        }else {
            callback.onContinue(postcard);
        }
    }

    @Override
    public void init(Context context) {

    }
}
